import 'package:favor_cate/core/model/meal_model.dart';
import 'package:favor_cate/core/services/meal_request.dart';
import 'package:flutter/cupertino.dart';

import 'filter_view_model.dart';

class MealViewModel extends ChangeNotifier{
  List<MealModel> _meals = [];

  FilterViewModel? _filterViewModel;


  MealViewModel() {
    MealRequest.getMealDate().then((value) {
      _meals = value;
      notifyListeners();
    });
  }

  List<MealModel> get meals { return _meals.where((meal) {
    if(_filterViewModel!.isGlutenFree && !meal.isGlutenFree) return false;
    if(_filterViewModel!.isLactoseFree && !meal.isLactoseFree) return false;
    if(_filterViewModel!.isVegan && !meal.isVegan) return false;
    if(_filterViewModel!.isVegetarian && !meal.isVegetarian) return false;
    return true;

  } ).toList();}

  void update(FilterViewModel filterViewModel) {
    _filterViewModel = filterViewModel;
  }

}